﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceProcess;
using Stone.Library.Common;

namespace Stone.Host
{
    public class ServiceHelp
    {
        /// <summary>
        /// 开启服务
        /// </summary>
        public static void StartService()
        {
            msdtcCheck();
            ServiceHostGroup.StartAllConfiguredServices();
        }
        /// <summary>
        /// 检查,MSDTC,并开启
        /// </summary>
        private static void msdtcCheck()
        {
            try
            {
                ServiceController sc = new ServiceController("MSDTC");
                if (sc.Status.ToString() != "Running")
                {
                    sc.Start();
                    LogManger.WriteSuccessLogWin("服务状态为：" + sc.Status.ToString() + "成功启动");
                }
                else
                {
                    LogManger.WriteSuccessLogWin("MSDTC服务已经启动");
                }
            }
            catch (Exception ex)
            {
                LogManger.WriteErrorLogWin("开启MSDTC服务异常：" + ex.Message);
            }
        }
    }
}
